<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:sec="http://www.springframework.org/security/facelets/tags">

	<ui:composition template="/faces/manager/xhtml/templates/template.xhtml">
		<ui:define name="manager-content">
			<p:growl id="messages" showDetail="true" sticky="true" />  
			<table id="manager-content-panel" cellpadding="0" cellspacing="1">
				<tr>
					<td id="manager-content-header">
						<h:form>				
							<p:breadCrumb style="width:810px;">
								<p:menuitem value="#{msg['manager.menu.navigator.home']}"/>
								<p:menuitem ajax="false" value="#{msg['manager.menu.navigator.admin']}" action="/faces/manager/xhtml/main.xhtml" />
								<p:menuitem ajax="false" value="#{msg['manager.menu.navigator.anuncio']}" action="/faces/manager/xhtml/anuncio/list.xhtml" />
								<p:menuitem value="#{msg['manager.menu.navigator.anuncio.create']}" />
							</p:breadCrumb>
						</h:form>
					</td>
				</tr>
				<tr>
					<td id="manager-content-body">
						<h:form id="form-anuncio">			        	 					
							<p:fieldset legend="#{msg['manager.menu.left.admin.anuncio.title']}" styleClass="manager-fieldset-content"> 									
								<p:spacer height="20px" />
								<p:outputPanel id="form-anuncio">
									<p:panel id="empresa">
										<table cellpadding="0" cellspacing="0">
											<sec:ifAnyGranted roles="ADMIN,IMOBILIARIA">
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.lancamento']}" />:											
													</td>
													<td class="form-column-value">
														<h:selectBooleanCheckbox value="#{anuncioController.anuncio.lancamento}" />
													</td>
													<td class="form-column-error"></td>
												</tr>
											</sec:ifAnyGranted>											
											<sec:ifAllGranted roles="ADMIN">
												<tr>
													<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.cliente']}" />:</td>
													<td class="form-column-value">
														<h:selectOneMenu id="cliente" value="#{anuncioController.anuncio.cliente.id}" styleClass="selectOneMenuForm">		               		
										               		<f:selectItems value="#{anuncioController.clientes}" var="cliente" itemLabel="#{cliente.pessoa.nome}" itemValue="#{cliente.id}" />
										               		<f:ajax event="change" execute="@this" render="representante" listener="#{anuncioController.loadRepresentantes}"/>       		
										            	</h:selectOneMenu>
													</td>
													<td class="form-column-error"></td>
												</tr>
											</sec:ifAllGranted>
											<sec:ifAnyGranted roles="ADMIN,IMOBILIARIA">
												<tr>
													<td class="form-column-label">
														<h:outputText  value="#{msg['manager.anuncio.create.representante']}" />:
													</td>
													<td class="form-column-value">
														<h:selectOneMenu id="representante" value="#{anuncioController.anuncio.representante.id}" styleClass="selectOneMenuForm" disabled="#{anuncioController.emptyRepresentantes}">	
															<f:selectItem itemLabel="" itemValue=""/>	               		
										               		<f:selectItems value="#{anuncioController.representantes}" var="rep" itemLabel="#{rep.pessoa.nome}" itemValue="#{rep.id}" />
									            		</h:selectOneMenu>
													</td>
													<td class="form-column-error"></td>
												</tr>
											</sec:ifAnyGranted>																					
											<sec:ifAllGranted roles="ADMIN">
												<tr>
													<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.empresa.ramo']}" />:</td>
													<td class="form-column-value">
														<h:selectOneMenu id="ramo" value="#{anuncioController.anuncio.ramo.id}" styleClass="selectOneMenuForm">		               		
										               		<f:selectItems value="#{anuncioController.ramos}" var="ramo" itemLabel="#{ramo.nome}" itemValue="#{ramo.id}" />
										               		<f:ajax event="change" execute="@this" render="imobiliario-panel" />       		
										            	</h:selectOneMenu>
													</td>
													<td class="form-column-error"></td>
												</tr>												
											</sec:ifAllGranted>
											<tr>
												<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.empresa.servico']}" />:</td>
												<td class="form-column-value">
													<h:selectOneMenu id="servico" value="#{anuncioController.anuncio.servico.id}" styleClass="selectOneMenuForm">		               		
									               		<f:selectItems value="#{anuncioController.servicos}" var="servico" itemLabel="#{servico.nome}" itemValue="#{servico.id}" />       		
									            	</h:selectOneMenu>
												</td>
												<td class="form-column-error"></td>
											</tr>											
											<tr>
												<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.empresa.nome']}" />:</td>
												<td class="form-column-value">
													<p:inputText id="nome" value="#{anuncioController.anuncio.empresa.pessoaJuridica.nome}" styleClass="inputText" 
						               					required="true" label="#{msg['manager.anuncio.create.empresa.nome']}" />
												</td>
												<td class="form-column-error"><p:message for="nome" /></td>
											</tr>
											<sec:ifAllGranted roles="ADMIN">
												<tr>
													<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.empresa.razaoSocial']}" />:</td>
													<td class="form-column-value">
														<p:inputText id="razaoSocial" value="#{anuncioController.anuncio.empresa.pessoaJuridica.razaoSocial}" styleClass="inputText" 
							               					required="false" label="#{msg['manager.anuncio.create.empresa.razaoSocial']}" />
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.empresa.cnpj']}" />:</td>
													<td class="form-column-value">
														<p:inputMask id="cnpj" value="#{anuncioController.anuncio.empresa.pessoaJuridica.cnpj}" styleClass="inputText" 
							               					required="false" label="#{msg['manager.anuncio.create.empresa.cnpj']}" mask="99.999.999/9999-99" />
													</td>
													<td class="form-column-error"><p:message for="cnpj" /></td>
												</tr>
											</sec:ifAllGranted>
											<tr>
												<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.empresa.descricao']}" />:</td>
												<td class="form-column-value">
													<p:inputTextarea id="descricao" value="#{anuncioController.anuncio.descricao}" styleClass="inputTextArea" 
														required="false" label="#{msg['manager.anuncio.create.empresa.descricao']}" maxHeight="120" maxlength="200"/>
												</td>
												<td class="form-column-error"></td>
											</tr>											
										</table>
									</p:panel>
									<p:spacer height="5px"/>
									<p:outputPanel id="imobiliario-panel">
										<p:panel id="imobiliario" rendered="#{anuncioController.anuncio.ramo.id == 4}">
											<table cellpadding="0" cellspacing="0">
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.imovel.proprietario']}" />:
													</td>
													<td class="form-column-value">
														<h:selectOneMenu id="slc_proprietario" styleClass="selectOneMenuForm" value="#{anuncioController.proprietario}">
								               				<f:selectItems value="#{anuncioController.proprietarios}" var="proprietario" itemLabel="#{proprietario}" itemValue="#{proprietario.value}"/>
							               				</h:selectOneMenu>
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.imovel.negociacao']}" />:
													</td>
													<td class="form-column-value">
														<h:selectOneMenu id="slc_negociacao" styleClass="selectOneMenuForm" value="#{anuncioController.tipoNegociacao}">
								               				<f:selectItems value="#{anuncioController.tiposNegociacao}" var="tipo" itemLabel="#{tipo}" itemValue="#{tipo.value}"/>
							               				</h:selectOneMenu>													
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.imovel.categoria']}" />:
													</td>
													<td class="form-column-value">
														<h:selectOneMenu id="slc_categoria" styleClass="selectOneMenuForm" value="#{anuncioController.categoria.id}">
								               				<f:selectItems value="#{anuncioController.categorias}" var="categoria" itemLabel="#{categoria.nome}" itemValue="#{categoria.id}"/>
								               				<f:ajax event="change" execute="@this" render="slc_subcategoria" listener="#{anuncioController.loadSubCategorias}" />      
							               				</h:selectOneMenu>													
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.imovel.subcategoria']}" />:
													</td>
													<td class="form-column-value">
														<h:selectOneMenu id="slc_subcategoria" styleClass="selectOneMenuForm" value="#{anuncioController.imovel.subCategoria.id}">
								               				<f:selectItems value="#{anuncioController.categoria.subCategorias}" var="sub" itemLabel="#{sub.nome}" itemValue="#{sub.id}"/>
							               				</h:selectOneMenu>													
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.imovel.dormitorios']}" />:
													</td>
													<td class="form-column-value">
														<h:selectOneMenu id="slc_dormitorio" styleClass="selectOneMenuForm" value="#{anuncioController.imovel.dormitorios}">
															<f:selectItem itemLabel="#{msg['template.selecione.option.label']}" itemValue=""/>
															<f:selectItem itemLabel="1 - Dormitório" itemValue="1"/>
															<f:selectItem itemLabel="2 - Dormitórios" itemValue="2"/>
															<f:selectItem itemLabel="3 - Dormitórios" itemValue="3"/>
															<f:selectItem itemLabel="4 - Dormitórios" itemValue="4"/>
															<f:selectItem itemLabel="5 - Dormitórios" itemValue="5"/>
															<f:selectItem itemLabel="6 - Dormitórios" itemValue="6"/>
															<f:selectItem itemLabel="7 - Dormitórios" itemValue="7"/>
															<f:selectItem itemLabel="8 ou + Dormitório" itemValue="8"/>											
														</h:selectOneMenu>
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.imovel.suites']}" />:
													</td>
													<td class="form-column-value">
														<h:selectOneMenu id="slc_suite" styleClass="selectOneMenuForm" value="#{anuncioController.imovel.suites}">
															<f:selectItem itemLabel="#{msg['template.selecione.option.label']}" itemValue=""/>
															<f:selectItem itemLabel="1 - Suíte" itemValue="1"/>
															<f:selectItem itemLabel="2 - Suítes" itemValue="2"/>
															<f:selectItem itemLabel="3 - Suítes" itemValue="3"/>
															<f:selectItem itemLabel="4 - Suítes" itemValue="4"/>
															<f:selectItem itemLabel="5 ou + Suítes" itemValue="5"/>																										
														</h:selectOneMenu>
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.imovel.banheiros']}" />:
													</td>
													<td class="form-column-value">
														<h:selectOneMenu id="slc_banheiro" styleClass="selectOneMenuForm" value="#{anuncioController.imovel.banheiros}">														
															<f:selectItem itemLabel="#{msg['template.selecione.option.label']}" itemValue=""/>
															<f:selectItem itemLabel="1 - Banheiro" itemValue="1"/>
															<f:selectItem itemLabel="2 - Banheiros" itemValue="2"/>
															<f:selectItem itemLabel="3 - Banheiros" itemValue="3"/>
															<f:selectItem itemLabel="4 - Banheiros" itemValue="4"/>
															<f:selectItem itemLabel="5 ou + Banheiros" itemValue="5"/>																											
														</h:selectOneMenu>
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.imovel.garagens']}" />:	
													</td>
													<td class="form-column-value">
														<h:selectOneMenu id="slc_garagem" styleClass="selectOneMenuForm" value="#{anuncioController.imovel.garagens}">
															<f:selectItem itemLabel="#{msg['template.selecione.option.label']}" itemValue=""/>
															<f:selectItem itemLabel="1 - Garagem" itemValue="1"/>
															<f:selectItem itemLabel="2 - Garagens" itemValue="2"/>
															<f:selectItem itemLabel="3 - Garagens" itemValue="3"/>
															<f:selectItem itemLabel="4 - Garagens" itemValue="4"/>
															<f:selectItem itemLabel="5 ou + Garagens" itemValue="5"/>									
														</h:selectOneMenu>
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.imovel.preco']}" />:
													</td>
													<td class="form-column-value">
														<p:inputText id="txt_preco" value="#{anuncioController.preco}" styleClass="inputText" required="false"/> 
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label">
														<h:outputText value="#{msg['manager.anuncio.create.imovel.areaUtil']}" />:
													</td>
													<td class="form-column-value">														
														<p:inputText id="txt_area_util" value="#{anuncioController.areaUtil}" styleClass="inputText" />
													</td>
													<td class="form-column-error"></td>
												</tr>
											</table>
										</p:panel>
									</p:outputPanel>
									<sec:ifAllGranted roles="ADMIN">
										<p:spacer height="5px"/>
										<p:panel id="contato">
											<table cellpadding="0" cellspacing="0">
												<tr>
													<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.contato.site']}" />:</td>
													<td class="form-column-value">
														<p:inputText id="site" value="#{anuncioController.anuncio.empresa.site}" styleClass="inputText" 
							               					required="false" label="#{msg['manager.anuncio.create.contato.site']}"/>
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.contato.email']}" />:</td>
													<td class="form-column-value">
														<p:inputText id="email" value="#{anuncioController.anuncio.empresa.email}" styleClass="inputText" 
							               					required="false" label="#{msg['manager.anuncio.create.contato.email']}"/>
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.contato.telefone.fixo']}" />:</td>
													<td class="form-column-value">
														<p:inputMask id="telefoneFixo" value="#{anuncioController.anuncio.empresa.telefoneFixo}" styleClass="inputText" 
							               					required="false" label="#{msg['manager.anuncio.create.contato.telefone.fixo']}" mask="(99)9999-9999" />
													</td>
													<td class="form-column-error"></td>
												</tr>
												<tr>
													<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.contato.telefone.celular']}" />:</td>
													<td class="form-column-value">
														<p:inputMask id="telefoneCelular" value="#{anuncioController.anuncio.empresa.telefoneCelular}" styleClass="inputText" 
							               					required="false" label="#{msg['manager.anuncio.create.contato.telefone.celular']}" mask="(99)9999-9999" />
													</td>
													<td class="form-column-error"></td>
												</tr>											
											</table>
										</p:panel>
									</sec:ifAllGranted>
									<p:spacer height="5px"/>
									<p:panel id="endereco">
										<table cellpadding="0" cellspacing="0">
											<tr>
												<td class="form-column-label"><h:outputText value="#{msg['manager.anuncio.create.endereco.cep']}" />:</td>
												<td class="form-column-value">
													<p:inputMask id="cep" styleClass="inputText" value="#{anuncioController.anuncio.empresa.endereco.cep}" 
						              					required="false" label="#{msg['manager.anuncio.create.endereco.cep']}" mask="99999-999">
						              				</p:inputMask>
												</td>
												<td class="form-column-error"><p:message for="cep" /></td>
											</tr>
											<tr>
												<td class="form-column-label"><h:outputText value="#{msg['manager.anuncio.create.endereco.rua']}" />:</td>
												<td class="form-column-value">													
						              				<p:inputText id="rua" styleClass="inputText" value="#{anuncioController.anuncio.empresa.endereco.rua}" 
						              					required="false" label="#{msg['manager.anuncio.create.endereco.rua']}">
						              				</p:inputText>
												</td>
												<td class="form-column-error"><p:message for="rua" /></td>
											</tr>
											<tr>
												<td class="form-column-label"><h:outputText value="#{msg['manager.anuncio.create.endereco.numero']}" />:</td>
												<td class="form-column-value">
													<p:inputText id="numero" styleClass="inputText" value="#{anuncioController.anuncio.empresa.endereco.numero}" 
						              					required="false" label="#{msg['manager.anuncio.create.endereco.numero']}" maxlength="4" >
						              				</p:inputText>
												</td>
												<td class="form-column-error"></td>
											</tr>
											<tr>
												<td class="form-column-label"><h:outputText value="#{msg['manager.anuncio.create.endereco.complemento']}" />:</td>
												<td class="form-column-value">
													<p:inputText id="complemento" styleClass="inputText" value="#{anuncioController.anuncio.empresa.endereco.complemento}" 
						              					required="false" label="#{msg['manager.anuncio.create.endereco.complemento']}" >
						              				</p:inputText>
												</td>
												<td class="form-column-error"></td>
											</tr>
											<tr>
												<td class="form-column-label"><h:outputText value="#{msg['manager.anuncio.create.endereco.edificio']}" />:</td>
												<td class="form-column-value">
													<p:inputText id="edificio" styleClass="inputText" value="#{anuncioController.anuncio.empresa.endereco.edificio}" 
						              					required="false" label="#{msg['manager.anuncio.create.endereco.edificio']}" >
						              				</p:inputText>
												</td>
												<td class="form-column-error"></td>
											</tr>
											<tr>
												<td class="form-column-label"><h:outputText value="#{msg['manager.anuncio.create.endereco.bairro']}" />:</td>
												<td class="form-column-value">
													<p:inputText id="bairro" styleClass="inputText" value="#{anuncioController.anuncio.empresa.endereco.bairro}" 
						              					required="true" label="#{msg['manager.anuncio.create.endereco.bairro']}" >
						              				</p:inputText>
												</td>
												<td class="form-column-error"><p:message for="bairro" /></td>
											</tr>
											<tr>
												<td class="form-column-label"><h:outputText  value="#{msg['manager.anuncio.create.endereco.estado']}" />:</td>
												<td class="form-column-value">
													<h:selectOneMenu id="estado" value="#{anuncioController.estado}"  styleClass="selectOneMenuForm" converter="#{simpleEntityConverter}">		               		
									               		<f:selectItems value="#{anuncioController.estados}" var="estado" itemLabel="#{estado.nome}" itemValue="#{estado}" />
									               		<f:ajax listener="#{anuncioController.reloadMunicipios}" event="change" execute="@this" render="municipio" />       		
									            	</h:selectOneMenu>
												</td>
												<td class="form-column-error"></td>
											</tr>
											<tr>
												<td class="form-column-label"><h:outputText value="#{msg['body.searchpanel.cidade']}" />:</td>
												<td class="form-column-value">
													 <h:selectOneMenu id="municipio" styleClass="selectOneMenuForm" value="#{anuncioController.anuncio.empresa.endereco.municipio.id}">
									               		<f:selectItems value="#{anuncioController.municipios}" var="municipio" itemLabel="#{municipio.nome}" itemValue="#{municipio.id}" />
									               </h:selectOneMenu>
												</td>
												<td class="form-column-error"></td>
											</tr>
										</table>
									</p:panel>
									
								</p:outputPanel>
								<p:spacer height="20px" />
								<table id="panel-buttons" cellpadding="0" cellspacing="0">
									<tr>
										<td>
											<p:commandButton value="#{msg['manager.anuncio.button.save']}" action="#{anuncioController.save}" ajax="false" icon="save-button" update="messages"/>
											<p:spacer width="10px" />
											<p:commandButton value="#{msg['manager.anuncio.button.attach']}" ajax="true" icon="attach-button" oncomplete="anuncioDialog.show()"/>
										</td>
									</tr>
								</table>
								<p:spacer height="5px" />								
							</p:fieldset>
						</h:form>
					</td>
				</tr>
			</table>
			<p:dialog header="#{msg['manager.anuncio.create.anexo.imagens']}" widgetVar="anuncioDialog" resizable="false"  
              width="600" height="400" modal="true" closeListener="#{anuncioController.sincronizaAlbum}">  
  				<h:form id="form-image" enctype="multipart/form-data" prependId="false">		  				
  					<table class="photo-panel-upload" cellpadding="0" cellspacing="0">
  						<tr>
  							<td><p:messages id="msg-error" showDetail="true"/></td>
  						</tr>
  						<tr>
  							<td>
  								<p:panel>	
  									 <p:fileUpload fileUploadListener="${anuncioController.handleFileUpload}"  
							            mode="advanced"   
							            update=":form-image:photo-list :form-image:msg-error"
							            sizeLimit="2097152"
							            label="${msg['manager.anuncio.button.upload.browse']}"
							            allowTypes="/(\.|\/)(jpe?g|png)$/"/>   												        	 					        	 			        	 			
		              			</p:panel>					
  							</td>
  						</tr>
  					</table>
  					<p:spacer height="5px"/>
					<p:outputPanel id="photo-list">		
								        	 					        	 		
      	 				<p:dataTable var="photo" value="#{anuncioController.albumAtivo}">        	 					   	 								        	 					       	 				
       	 					
       	 					<p:column headerText="#{msg['manager.anuncio.button.album.arquivo']}" >		        	 						
       	 						<h:outputText value="#{photo.nome}"/>
       	 					</p:column>
       	 					
       	 					<p:column >		        	 					
       	 						<p:commandLink update=":form-image:photo-list" actionListener="#{anuncioController.removeFile}" ajax="true">
       	 							<f:param name="photo" value="#{photo.nome}" />
       	 							<h:graphicImage value="#{resource['images:icons/16x16/delete.png']}" />
       	 						</p:commandLink>
       	 					</p:column>    
       	 					       	 										      	 					        	 					
       	 				</p:dataTable>
	       	 			
             		</p:outputPanel>		        			              		
              		          		
             	</h:form>
  			</p:dialog>				
		</ui:define>
	</ui:composition>
</html>